//
//  YGNavigationController.swift
//  SwiftWebo
//
//  Created by 王勇 on 2018/5/26.
//  Copyright © 2018年 Brave. All rights reserved.
//

import UIKit

class YGNavigationController: UINavigationController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认导航 Navigationbar
        navigationBar.isHidden = true
        
        
    }
    
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        print(viewController)
       
        // 不是根控制器就隐藏tabar
        if childViewControllers.count > 0 {
           
            viewController.hidesBottomBarWhenPushed = true //TODO:隐藏tabbar
            
            if let vc = viewController as? YGBaseViewController {
              
                var title = "返回"
                
                // 判断控制器级数 只有一个子控制器显示栈底标题
                if childViewControllers.count == 1 {
                    // 显示首页标题
                    title = childViewControllers.first?.title ?? "返回"
                    
                }
                // 取出自定义item
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 16, target: self, action: #selector(popToPare))
                
            }
    
        }
        
       
        
        super.pushViewController(viewController, animated: true)
        
    }
   
    // 返回上一级
    @objc private func popToPare(){
        
        popViewController(animated: true)
    }
}
